//
//  CZFactory.swift
//  Weibo24
//
//  Created by apple on 16/3/8.
//  Copyright © 2016年 apple. All rights reserved.
//

import UIKit

/*
    工厂设计模式: 是由父类去定义一些协议,子类去实现

    举例: 煎饼果子 -> 果子,煎饼,鸡蛋,葱花,
            豆浆

    抽象工厂
*/
class CZFactory: NSObject {

    class func getButton(title: String?,image: String?,selectedImage: String?,tag: Int,target:AnyObject?,action: Selector) -> UIButton {
        
        let button = UIButton(type: UIButtonType.Custom)
        
        button.setTitle(title, forState: UIControlState.Normal)
        if let Oimage = image{
            
            button.setBackgroundImage(UIImage(named: Oimage), forState: UIControlState.Normal)
            
        }
        
        if let OSelectImage = selectedImage {
            
            button.setBackgroundImage(UIImage(named: OSelectImage), forState: UIControlState.Selected)
        }
        
        button.tag = tag
        
        button.addTarget(target, action: action, forControlEvents: UIControlEvents.TouchUpInside)
        
        return button
    }
    
}
